// 审核计划表
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="评审时间">
        <el-date-picker
          v-model="dateRange"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 240px"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['manageAudit:inAudit:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['manageAudit:inAudit:edit']"
          >修改</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:user:remove']"
          >删除</el-button
        > -->
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['manageAudit:inAudit:export']"
          >导出</el-button
        >
      </el-col>
       <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="printBox"
          v-hasPermi="['manageAudit:inAudit:print']"
          >打印</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table
      @selection-change="handleSelectionChange"
      fit
      v-loading="loading"
      border
      :data="dataList"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column min-width="200" show-overflow-tooltip label="年度">
        <template slot-scope="scope">
          <span
            >{{
              scope.row.innerManagerAudit.auditYear
            }}年度管理评审工作计划</span
          >
        </template>
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="主持人"
        prop="host"
        min-width="120"
      />
      <el-table-column
        show-overflow-tooltip
        label="记录人"
        prop="logUser"
        min-width="120"
      />
      <el-table-column
        show-overflow-tooltip
        label="管评时间"
        min-width="120"
        prop="auditDate"
      />

      <!-- <el-table-column label="是否启用" align="center">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.effectStatus"
            :active-value="1"
            :inactive-value="0"
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column> -->
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="240"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            v-hasPermi="['manageAudit:inAudit:info']"
            @click="handleDetail(scope.row)"
            >详情</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['manageAudit:inAudit:edit']"
            >修改</el-button
          >
            <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['manageAudit:inAudit:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog
      :visible.sync="openFile"
      :title="type == 1 ? '首次签到表' : type == 2 ? '末次签到表' : '总结报告'"
      width="800"
      append-to-body
    >
      <el-form
        :disabled="isEdit"
        ref="elForm"
        :model="formData"
        :rules="rules"
        size="medium"
        label-width="120px"
      >
        <el-form-item label="" prop="filePath">
          <fileUpload
            :isDelete="!isEdit"
            v-model="formData.filePath"
          ></fileUpload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!isEdit">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="openFile = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 打印模板位置 -->
    <PrintBox
      :checkNum="9"
      :printRow="printList"
      :isPageSize="false"
      id="printBox"
    >
      <template slot="title" slot-scope="scope">
        <div style="margin-bottom: 10px">管理评审记录表 STET/B/13-2</div>
      </template>
      <template slot-scope="scope">
        <!-- 表格  class  table-page  必须-->
        <table
          style="border-collapse: collapse; table-layout: fixed"
          border="1"
          cellspacing="0"
          class="table-page"
        >
          <tr>
            <td style="width:20mm">主持人</td>
            <td style="width:30mm">{{ scope.item.host }}</td>
            <td style="width:30mm">记录人</td>
            <td style="width:45mm">{{ scope.item.logUser }}</td>
            <td style="width:40mm">管评时间</td>
            <td style="width:40mm">{{ scope.item.auditDate }}</td>
          </tr>
          <tr>
            <td>序号</td>
            <td colspan="2">评审项目</td>
            <td colspan="1">文件适应性</td>
            <td colspan="1">运行情况</td>
            <td colspan="1">单项结论</td>
          </tr>
          <tr v-for="(item,index) in dict.type.sys_manager_item">
            <td>{{index+1}}</td>
            <td colspan="2">{{item.label}}</td>
            <td colspan="1">{{checkItem(item,scope.item.infoList,'adapt')}}</td>
            <td colspan="1">{{checkItem(item,scope.item.infoList,'run')}}</td>
            <td colspan="1">{{checkItem(item,scope.item.infoList,'result')}}</td>
          </tr>
           <tr >
            <td colspan="6" >
             <div style="text-align:left; margin-left: 5mm;"> 说明：1.参加人员见培训/会议签到表。2.评审发言情况见发言记录。</div>
            </td>
           
          </tr>

          
        </table>
        <!-- 底部信息位置 -->

        <div class="page-bottom" style="page-break-after: always">
          <div class="desc">注：本表格自2021年6月1日起生效</div>
        </div>
      </template>
    </PrintBox>
  </div>
</template>

<script>
import {
  listmanagerLog,
  delmanagerLog,
  effectmanagerLog,
  signFile,
} from "@/api/quality/manageAudit/managerLog.js";
import printStyle from "@/utils/print.js";

export default {
  name: "check",
  dicts:["sys_manager_item"],
  data() {
    return {
      formData: { filePath: undefined },
      rules: {
        filePath: [
          {
            required: true,
            message: "附件不能为空",
            trigger: "change",
          },
        ],
      },

      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      dataList: [],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deviceName: undefined,
        operUserId: undefined,
        licenseNum: undefined,
        checkDate: null,
      },
      // 日期范围
      dateRange: [],
      openFile: false,
      type: 1,
      current: {}, 
      infos: [], //勾选的数据
      printList: [],
    };
  },
  created() {
    const str = sessionStorage.getItem('queryParams');
    if (str) {
      this.queryParams = JSON.parse(str);
      if (this.queryParams.startAuditDate) {
        this.dateRange.push(this.queryParams.startAuditDate, this.queryParams.endAuditDate)
      }
      setTimeout(() => {
        sessionStorage.removeItem('queryParams');
      }, 500)
    }
    this.getList();
  },
  methods: {
    checkItem(e,list,flag){
     let info  =  list.find(_e =>_e.item==e.value)

     return info&&info[flag]||''

    },
    printBox() {
      //infos  勾选的数据 如果有勾选就打印勾选。
      if (this.infos.length) {
        this.printList = this.infos;
      } else {
        //反之打印当前整个列表
        this.printList = this.dataList;
      }
      setTimeout(() => {
        document.title = "管理评审记录表 STET/B/13-2";

        this.$print({
          printable: "printBox", //打印区域id
          type: "html", //打印类型是html
          scanStyles: false,
          targetStyles: ["*"],
          style: this.workStyle(),
          onPrintDialogClose: () => {
            document.title = process.env.VUE_APP_TITLE;
          },
        });
      }, 500);
    },
    // 可以自定义样式  printStyle 是公共样式 切勿私自修改
    workStyle() {
      return `${printStyle}
        table,
        table tr th,
        table tr td {
          height:9.2mm;
          padding: 0px;
          font-size: 12px;
        }
        .desc{
        text-align: left; font-size: 12px; margin-top: 10px
      }
            .df {
                display: flex;
              }
      `;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.innerManagerLogId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
      this.infos = selection;

    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      sessionStorage.setItem('queryParams', JSON.stringify(this.queryParams));
      const configId = row.innerManagerLogId || this.ids;
      this.$router.push("./addInAudit?isEdit=true&id=" + configId);
    },
    handleDetail(row) {
      sessionStorage.setItem('queryParams', JSON.stringify(this.queryParams));
      this.$router.push("./addInAudit?isInfo=true&id=" + row.innerManagerLogId);
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleDelete":
          this.handleDelete(row);
          break;
        case "handleFileFirst":
          this.handleFile(row, 1);
          break;
        case "handleFileLast":
          this.handleFile(row, 2);
          break;
        case "handleSummary":
          this.handleFile(row, 3);
          break;
        case "handleCorrent":
          this.handleCorrent(row);
          break;
      }
    },
    handleCorrent(e) {
      sessionStorage.setItem('queryParams', JSON.stringify(this.queryParams));

      this.$router.push(
        "./addCorrect?innerManagerLogId=" + e.innerManagerLogId
      );
    },
    handleFile(row, type) {
      try {
        this.formData = { filePath: undefined };
        this.type = type;
        this.current = row;
        this.isEdit = false;
        if (this.type == 1 && this.current.firstSignFile) {
          this.formData.filePath = this.current.firstSignFile;
          this.isEdit = true;
        }
        if (this.type == 2 && this.current.endSignFile) {
          this.formData.filePath = this.current.endSignFile;
          this.isEdit = true;
        }
        if (this.type == 3 && this.current.report) {
          this.formData.filePath = this.current.report;
          this.isEdit = true;
        }
      } catch (error) {
        console.log(error);
      }
      this.openFile = true;
    },
    handleStatusChange(row) {
      let text = row.effectStatus == "1" ? "启用" : "禁用";
      this.$modal
        .confirm('确认要"' + text + '""' + row.innerManagerLogId + '"数据吗？')
        .then(function () {
          return effectmanagerLog(row.innerManagerLogId, row.effectStatus);
        })
        .then(() => {
          this.$modal.msgSuccess(text + "成功");
        })
        .catch(function () {
          row.effectStatus = row.effectStatus == "0" ? 1 : 0;
        });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const configId = row.innerManagerLogId || this.ids;
     
      this.$modal
         .confirm('是否确认删除' + row.innerManagerAudit.auditYear + '年度管理评审工作计划数据项？')
        .then(function () {
          return delmanagerLog(configId);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    handleAdd() {
      this.$router.push("./addInAudit");
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listmanagerLog(
        this.addDateRangeTime(
          this.queryParams,
          this.dateRange,
          "startAuditDate",
          "endAuditDate"
        )
      ).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleExport() {
      this.download(
        "system/managerLog/export",
        {
          ...this.queryParams,
        },
        `管理审查记录表_${this.parseTime(
          new Date().getTime(),
          "{y}-{m}-{d}"
        )}.xlsx`
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["elForm"].validate((valid) => {
        if (valid) {
          this.formData.type = this.type;
          this.formData.innerManagerLogId = this.current.innerManagerLogId;
          signFile(this.formData).then((response) => {
            this.$modal.msgSuccess("操作成功");
            this.openFile = false;
            this.getList();
          });
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
  img {
    width: 100%;
  }
}
</style>
